home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
033a
/
dircnt11.zip
/
DIRCOUNT.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1991-07-24
|
6KB
|
271 lines
(*
* DirCount - Count file directory entries and insert headers with
* file information.
*
* Written by Samuel H. Smith, 12-30-88
*
*)
const
version = 'DirCount 1.1, 07-24-91';
var
console: text;
ctlfd: text;
bbsname: string;
dirfile: string;
title: string;
dirnum: integer;
ibuf: array[1..20480] of byte;
obuf: array[1..20480] of byte;
line: string;
sizes: longint;
tsizes: longint;
files: word;
tfiles: word;
(* --------------------------------------------------------- *)
function itoa (n: longint): string;
var
tstr: string;
begin
str(n, tstr);
itoa := tstr;
end;
(* --------------------------------------------------------- *)
function insert_commas(s: string): string;
var
i: integer;
begin
i := length(s);
while i > 3 do
begin
dec(i,3);
insert(',',s,i+1);
end;
insert_commas := s;
end;
(* --------------------------------------------------------- *)
function numtostr(n: longint; width: integer): string;
var
s: string;
t: string;
p: integer;
begin
if n < 100000 then
s := insert_commas( itoa(n) ) + ' '
else
if n < 1024000 then
s := insert_commas( itoa(n shr 10) ) + ' K '
else
begin
str((n shr 10) / 1000:0:2,t);
s := insert_commas( copy(t,1,length(t)-3) ) +
copy(t,length(t)-2,3) + ' MEG';
end;
if width = 0 then
while s[length(s)] = ' ' do
dec(s[0]);
while length(s) < width do
s := ' ' + s;
numtostr := s;
end;
(* --------------------------------------------------------- *)
function isfile: boolean;
begin
isfile := (length(line) > 35) and
(line[26] = '-') and (line[29] = '-') and
(line[21] >= '0') and (line[21] <= '9') and
(line[24] >= '0') and (line[24] <= '9');
end;
(* --------------------------------------------------------- *)
procedure count_files;
var
size: longint;
err: integer;
tmp: string;
ifd: text;
begin
files := 0;
sizes := 0;
assign(ifd,dirfile);
{$i-} reset(ifd); {$i+}
if ioresult <> 0 then
begin
writeln(console,'Can''t open DIR file ',dirfile);
halt(99);
end;
setTextBuf(ifd,ibuf);
write(console,' Counting: ',dirfile,'':10,^M);
while not eof(ifd) do
begin
readln(ifd,line);
if isfile then
begin
inc(files);
tmp := copy(line,13,9);
while tmp[1] = ' ' do
delete(tmp,1,1);
val(tmp,size,err);
sizes := sizes + size;
end;
end;
close(ifd);
end;
(* --------------------------------------------------------- *)
procedure update_dirfile;
var
ifd: text;
ofd: text;
tmp: string;
begin
assign(ifd,dirfile);
{$i-} reset(ifd); {$i+}
if ioresult <> 0 then
begin
writeln(console,'Can''t open DIR file ',dirfile);
halt(99);
end;
assign(ofd,dirfile+'$');
{$i-} rewrite(ofd); {$i+}
if ioresult <> 0 then
begin
writeln(console,'Can''t create tempfile ',dirfile,'$');
halt(99);
end;
setTextBuf(ifd,ibuf);
setTextBuf(ofd,obuf);
write(console,'Formatting: ',dirfile,'':10,^M);
repeat
readln(ifd,line);
until isfile or eof(ifd);
writeln(ofd);
writeln(ofd,'':38-length(bbsname) div 2,bbsname);
writeln(ofd);
writeln(ofd,'':38-length(title) div 2,title);
tmp := itoa(files) + ' files using ' + numtostr(sizes,0) + ' bytes';
writeln(ofd,'':38-length(tmp) div 2,tmp);
writeln(ofd);
writeln(ofd,' File Name Size Date File Description');
writeln(ofd,'------------ ------- -------- ---------------------------------------------');
writeln(ofd);
writeln(ofd,line);
while not eof(ifd) do
begin
readln(ifd,line);
writeln(ofd,line);
end;
close(ofd);
close(ifd);
{$i-} erase(ifd); {$i+}
if ioresult <> 0 then
begin
writeln(console,'Can''t erase old dirfile ',dirfile);
halt(99);
end;
{$i-} rename(ofd,dirfile); {$i+}
if ioresult <> 0 then
begin
writeln(console,'Can''t rename new dirfile ',dirfile,'$ to ',dirfile);
halt(99);
end;
end;
(* --------------------------------------------------------- *)
begin
assign(console,'CON');
rewrite(console);
writeln(console,version,'; Copyright 1988, 1991 Samuel H. Smith');
writeln(console);
if paramcount <> 1 then
begin
writeln(console,'Usage: DirCount configfile [>summary]');
writeln(console,'Example: DirCount COUNT.CNF >\PCB\GEN\BLT16');
halt(99);
end;
assign(ctlfd,paramstr(1));
{$i-} reset(ctlfd); {$i+}
if ioresult <> 0 then
begin
writeln(console,'Can''t open configuration file ',paramstr(1));
halt(99);
end;
readln(ctlfd,bbsname);
dirnum := 0;
tfiles := 0;
tsizes := 0;
writeln;
writeln('':38-length(bbsname) div 2,bbsname);
writeln;
writeln(' Dir Files Bytes Description');
writeln('----- ------- ------------- ----------------------------------------------');
while not eof(ctlfd) do
begin
readln(ctlfd,dirfile);
readln(ctlfd,title);
inc(dirnum);
count_files;
writeln(insert_commas( itoa(dirnum)):4,
insert_commas( itoa(files)):8,
numtostr(sizes,14),' ',title);
tfiles := tfiles + files;
tsizes := tsizes + sizes;
update_dirfile;
end;
write(console,'':60,^M);
close(ctlfd);
writeln(' ======= ===============');
writeln(insert_commas( itoa(tfiles) ):12,numtostr(tsizes,14));
end.